<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Login extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see https://codeigniter.com/user_guide/general/urls.html
	 */
	
	 function __construct()
	 {
		parent::__construct();
		$this->load->model('Login_m','L');
		
	 }
	public function index()
	{
		$pass = 'fuman123';
		//echo md5(crypt($pass,substr($pass,0,2)));
		//die;
		
		if($_COOKIE["username"] && $_COOKIE["userid"])
		{
			header("Location: /Welcome");die;
		}
		$this -> tpl -> display("login/login.tpl",'','',1);
	}
	
	public function logincheck()
	{
		
		$username = $this->input->post('username');
		$password = $this->input->post('password');
		$rs = $this->L->login_check($username,$password);
		

		
		//
		
			//header("Location: /user/onedit?uid=".$_COOKIE["userid"]);
			echo $rs;
			die;
	}
	public function logout()
	{
		setcookie("salt","exsoftorder");
		delete_cookie("userid");
		delete_cookie("username");
		delete_cookie("user_login");
		delete_cookie("classid");
		delete_cookie("department");
		delete_cookie("shopname");
		delete_cookie("power");
		delete_cookie("seawarehouse");
		delete_cookie("ext_userid");	//外部组成员ID
		delete_cookie("ext_userid_open_goods");	//外部组成员ID
		delete_cookie("external_id");	//外部组成员ID
		delete_cookie("notext_userid");	//外部组成员ID
		header("Location: /login");
	}
	
}
